package com.orhon.smartcampus.modules.teacher.mutation;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.orhon.smartcampus.basicComponents.Result;
import com.orhon.smartcampus.modules.teacher.dao.TInformationDao;
import com.orhon.smartcampus.modules.teacher.entity.TInformation;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

@Component
public class DeleteTeacherMutation implements DataFetcher {


    @Autowired
    TInformationDao tInformationDao;

    /**
     * 教师删除接口
     * editor : ths
     */
    @Override
    public Object get(DataFetchingEnvironment environment) throws Exception {
        if (environment.getArgument("id") != null) {
            List<Integer> ids = environment.getArgument("id");
            ids.forEach(id -> {
                    TInformation item = tInformationDao.get(TInformation.class, Long.valueOf(id));
                    item.setDeletedAt( new Date());
                  try {
                       tInformationDao.update(item);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            );
            return Result.ok();
        }
        return Result.error();
    }
}

